package com.example.cinema.activity;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import com.example.cinema.R;
import com.example.cinema.adapter.UserMasgAdapter;
import com.example.cinema.adapter.UserMasgItemAdapter;
import com.example.cinema.bindingdata.UserMassageItemData;
import com.example.cinema.bindingdata.UserMassgData;
import com.example.cinema.databinding.ActivityUsermsgContentBinding;

import java.util.ArrayList;
import java.util.List;

public class ActivityUsermsgContent extends AppCompatActivity {


    private ActivityUsermsgContentBinding  AUC;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AUC = DataBindingUtil.setContentView(this, R.layout.activity_usermsg_content);
        init();
        initlistener();
        if(Build.VERSION.SDK_INT>11 && Build.VERSION.SDK_INT<19)
        {
            View view = getWindow().getDecorView();
            view.setSystemUiVisibility(View.GONE);
        }else if(Build.VERSION.SDK_INT>=19){
            View view = getWindow().getDecorView();
            int UIOP = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY|View.SYSTEM_UI_FLAG_FULLSCREEN;
            view.setSystemUiVisibility(UIOP);
        }
    }

    private void initlistener() {
        //返回
        AUC.finsh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }

    //获取传递的消息并组装
    private void init() {
        Intent intent =  getIntent();
        String name = intent.getStringExtra("sendname");
        List<String> list = intent.getStringArrayListExtra("sendlist");
        String image = intent.getStringExtra("sendimg");
        UserMassgData data = new UserMassgData();
        data.msgsend.set(name);
        data.msgimg.set(image);
        AUC.setMassgdata(data);

        if(list==null)
        {
            Log.i("KKK","空的");
        }

        List<UserMassageItemData> listdata = new ArrayList<>();
        for (int i=0;i<list.size();i++)
        {
            UserMassageItemData itemData = new UserMassageItemData();
            itemData.sendnam.set(name);
            itemData.sendimg.set(image);
            itemData.sendmsg.set(list.get(i));
            Log.i("LLL",list.get(i));
            listdata.add(itemData);
        }
//
        UserMasgItemAdapter adapter = new UserMasgItemAdapter<UserMassageItemData>(getApplicationContext(),listdata,R.layout.user_msg_centext_item);
        AUC.msglist.setAdapter(adapter);
    }
}
